let gulp = require("gulp");
let cssmin = require("gulp-cssmin");
let uglify = require("gulp-uglify");
let htmlmin = require('gulp-htmlmin');
let gulpclean = require("gulp-clean");
let webserver = require('gulp-webserver');
// let gulpBable = require("gulp-babel");
function css() {
    return gulp.src("./src/css/**").pipe(cssmin()).pipe(gulp.dest("./dist/css"));
}
function js() {
    return gulp.src("./src/js/**").pipe(uglify()).pipe(gulp.dest("./dist/js"))
}
function html() {
    return gulp.src("./src/html/**").pipe(htmlmin({
        collapseWhitespace: true, 
        removeEmptyAttributes: true, 
        minifyCSS: true, 
        minifyJS: true, 
    })).pipe(gulp.dest("./dist/html"))
}
function html2() {
    return gulp.src("./src/index.html").pipe(htmlmin({
        collapseWhitespace: true, 
        removeEmptyAttributes: true, 
        minifyCSS: true, 
        minifyJS: true, 
    })).pipe(gulp.dest("./dist/"))
}
function clean() {
    return gulp.src(["./dist"]).pipe(gulpclean());
}
function watch() {
    gulp.watch('./src/css', css);
    gulp.watch('./src/html', html);
    gulp.watch('./src/js', js);
}
function web() {
    return gulp.src("./dist").pipe(
        webserver({
            host: "localhost", // 域名
            port: 3000, // 监听的端口号，统一写 3000
            open: "./index.html", // 打开的页面，相对于 dist 文件夹来的目录
            livereload: true, // 浏览器自动刷新,
            proxies: [
                    {
                        source: "/api", 
                        target: "http://gz21071.com:60", //需要请求的接口
                    },
                ],
        })
    );
}
function data() {
    return gulp.src("./src/data/**").pipe(gulp.dest("./dist/data"));
}
exports.css = css;
exports.js = js;
exports.html = html;
exports.clean = clean;
exports.web = web;
exports.img = data;
exports.html2 = html2;
exports.build = gulp.series(clean, gulp.parallel(css, js, html,data,html2),web,watch);